import { defineStore } from 'pinia'
import { ref } from 'vue'
// 你可以任意命名 ` ()` 的返回值，但最好使用 store 的名字，同时以 `use` 开头且以 `Store` 结尾。
// (比如 `useUserStore`，`useCartStore`，`useProductStore`)
// 第一个参数是你的应用中 Store 的唯一 ID。
export const usePPTStore = defineStore('PPT-generation', () => {
  const isgeneratePPT = ref(true)
  const setGeneratePPT = (is) => {
    isgeneratePPT.value = is
  }
  return { isgeneratePPT, setGeneratePPT }
}, { persist: true })

export const useBlogStore = defineStore('Blog-generation', () => {
  const isgenerateBlog = ref(true)
  const setGenerateBlog = (is) => {
    isgenerateBlog.value = is
  }
  return { isgenerateBlog, setGenerateBlog }
}, { persist: true })
export const useEditor = defineStore('editor-util', () => {
  const isEditor = ref(true)
  const setEditor = (is) => {
    isEditor.value = is
  }
  return { isEditor, setEditor }
}, { persist: true })

export const useSSIDStore = defineStore('PPT-generation', () => {
  const ssid = ref('')
  const setSsid = (is) => {
    ssid.value = is
  }
  const getSsid = () => {
    return ssid.value
  }
  return { ssid, setSsid }
}, { persist: true })

export const usePortStore = defineStore('port', () => {

  const baseURL = ref('')
  const port = ref()
  function setPort (data) {
    port.value = data
  }
  function getPort () {
    return port.value.port
  }
  function getUserInfo () {
    return port.value.userinfo
  }
  function setUrl (url) {
    baseURL.value = url
  }
  //是否失效
  function isInvalid () {
    if (!port.value?.time && !port.value?.port || !port.value?.userinfo) return true
    return (new Date().getTime() - port.value.time) >= 3600000*12
  }
  return { port, setPort, getPort, isInvalid, getUserInfo,setUrl,baseURL }
}, { persist: true })
